package com.yxhl.zoume.core.user.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.activity.base.BaseActivityWithToolBar;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.user.ui.fragment.mywallet.ExpenseDetailFragment;
import com.yxhl.zoume.core.user.ui.fragment.mywallet.IncomeDetailFragment;
import com.yxhl.zoume.core.user.ui.fragment.mywallet.RefundDetailFragment;
import com.yxhl.zoume.core.user.ui.info.MyWalletEntry;
import com.yxhl.zoume.data.http.model.mywallet.TradeRecordBean;


/**
 * 项目名称：Ferrari
 * Created by menggod on 16/11/23 .
 */
public class MyWalletDetailActivity extends BaseActivityWithToolBar implements BaseView {

    private String orderSerial;
    private String mTradeType;

    public static Intent getCallingIntent(Activity activity ,TradeRecordBean tradeRecordBean ) {
        Intent intent = new Intent(activity, MyWalletDetailActivity.class);
        intent.putExtra(UIConstants.MyWallet.ARGUMENT_DETAIL_EVENT,tradeRecordBean);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        parseIntent();
        judgeDisplayDetailFragment(mTradeType);
    }

    private void parseIntent() {
        Intent intent = getIntent();
        if (intent!=null) {
            Bundle bundle = intent.getExtras();
            TradeRecordBean tradeRecord = (TradeRecordBean) bundle.get(UIConstants.MyWallet.ARGUMENT_DETAIL_EVENT);
            orderSerial = tradeRecord.getId();
            mTradeType = tradeRecord.getTypeOfTrade();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    /**
     * 显示相应的页面
     *
     * @param walletEntry
     */
    public void showRelevantFragment(MyWalletEntry walletEntry) {
        Fragment fragment = fragmentProvider(walletEntry);
        replaceFragment(R.id.fl_my_wallet_container, fragment, false);
    }

    /**
     * 显示对应的详情
     *
     * @param tradeType
     */
    public void judgeDisplayDetailFragment(String tradeType) {
        switch (tradeType) {
            case "USER_PAY":
            case "USER_RECHARGE_AND_PAY":
                showRelevantFragment(MyWalletEntry.USER_PAY);
                break;
            case "USER_RECHARGE":
                showRelevantFragment(MyWalletEntry.USER_RECHARGE);
                break;
            case "USER_REFUND":
                showRelevantFragment(MyWalletEntry.USER_REFUND);
                break;
            default:
                break;
        }
    }


    private Fragment fragmentProvider(MyWalletEntry walletEntry) {
        Fragment fragment;
        switch (walletEntry) {
            case USER_PAY: //支付详情
                fragment = ExpenseDetailFragment.newInstance(orderSerial);
                break;
            case USER_RECHARGE: //充值详情
                fragment = IncomeDetailFragment.newInstance(orderSerial);
                break;
            case USER_REFUND: // 退款详情
                fragment = RefundDetailFragment.newInstance(orderSerial);
                break;
            default:
                fragment = ExpenseDetailFragment.newInstance(orderSerial);
                break;
        }
        return fragment;
    }

    @Override
    protected void onHeaderLeftClick(View view) {
        onBackPressed();
    }

    @Override
    protected void onHeaderRightClick(View view) {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_my_wallet;
    }

    @Override
    protected void initializeInjector() {

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}
